import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: {},
    courseSrc: {},
    course: {}
  },
  mutations: {
    setUserInfo(state, user) {
      if (!user) {
        return
      }
      state.user = user
    },
    setCourseSrc(state, courseSrc) {
      if (!courseSrc) {
        return
      }
      state.courseSrc = courseSrc
    },
    setCourse(state, course) {
      if (!course) {
        return
      }
      state.course = course
    },
    getSearch(state, course) {
      if (!course) {
        return
      }
      state.searchCourse = course
    }
  },
  actions: {
    setUserInfo({
      commit
    }, user) {
      commit('setUserInfo', user)
    },
    setCourseSrc({
      commit
    }, courseSrc) {
      commit('setCourseSrc', courseSrc)
    },
    setCourse({commit}, course) {
      commit('setCourse', course)
    },
    getSearch({commit}, course) {
      commit('getSearch', course)
    }
  },
  modules: {}
})
